// 页面路径：store/index.js
//状态管理
import {
	createStore
} from 'vuex'
const store = createStore({
	//全局数据
	state: { //存放状态
		token: "",
		userInfo: {},
		//用户是否登录
		isAuth: false
	},
	//全局计算属性
	getters: {

	},
	//修改数据的方法
	mutations: {
		//保存用户信息
		saveLoginInfo(state, info) {
			info.data.avatar = "http://1.12.237.123:9000" + info.data.avatar
			state.userInfo = info.data
			state.isAuth = true
			uni.setStorageSync('isAuth', true)
			uni.setStorageSync('userInfo', info.data)
		},
		//更改登录状态
		setIsAuth(state) {
			state.isAuth = true
			uni.setStorageSync('isAuth', true)
		},
		//修改用户信息
		updateInfo(state, info) {
			info.avatar = "http://1.12.237.123:9000" + info.avatar
			state.userInfo = info
			uni.setStorageSync('userInfo', info)
		},
		//修改token
		updateToken(state, token) {
			state.token = token
			uni.setStorageSync("token", token)
		}
	},
	//全局操作方法
	actions: {

	}
})

export default store